package com.markerhub.controller;


import com.markerhub.entity.Charge;
import com.markerhub.entity.Statics;
import com.markerhub.repository.ChargeRepository;
import com.markerhub.repository.StaitcsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/charge")
public class ChargeHandler{
    @Autowired
    private ChargeRepository chargeRepository;
    @Autowired
    private StaitcsRepository staitcsRepository;

    @GetMapping("/findAll")
    public List<Charge> findALL(){
          GetAll();
        return chargeRepository.findAll();
    }

    void GetAll()
    {
        List<Statics> list = staitcsRepository.findAll();
        List<Charge> list1 = chargeRepository.findAll();
        int a=0,b=0,c=0;
        for (int i=0;i<list.size();i++){
            Statics statics = list.get(i);
            String str=statics.getA();
            if(str.equals("教研业绩量化")){
                a++;

            }else if(str.equals("教材业绩量化")){
                b++;
            }else if((str.equals("自然科学科研业绩量化"))){
                c++;
            }
        }
        for (int i=0;i<list1.size();i++){
            Charge charge = list1.get(i);
            if(i==0){
                charge.setNumber(a);

            }else if(i==1){
                charge.setNumber(b);
            }else if(i==2){
                charge.setNumber(c);
            }
            chargeRepository.save(charge);
        }
    }
    }

